package cn.bigcontainer.alt.workflow.extension.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import cn.bigcontainer.alt.common.entity.BigMap;
import cn.bigcontainer.alt.common.util.WoKit;
import cn.bigcontainer.alt.sys.util.SysUtil;
import cn.bigcontainer.alt.workflow.dto.MTaskDefinitionDto;
import cn.bigcontainer.alt.workflow.extension.TaskCandidateRouter;

@Component
@Primary
public class TaskCandidateRouterDefault implements TaskCandidateRouter {

    @Override
    public List<String> getTaskCandidates(MTaskDefinitionDto current, MTaskDefinitionDto next) {
        if (!WoKit.isEmpty(next.getTaskCandidateExpression())) {
            return next.parseTaskCandidateExpression(current);
        }
        BigMap<String, Object> request = current.getFormView().getApp().getObject().getRequest();
        return Arrays.asList(SysUtil.getCurrentUserWithException(request).getId().toString());
    }
}
